home *** CD-ROM | disk | FTP | other *** search
- Path: news.interpath.net!mercury!softbase
- From: softbase@mercury.interpath.net (Scott McMahan - Softbase Systems)
- Newsgroups: comp.lang.c
- Subject: Re: Tradition or what?
- Date: 7 Mar 1996 13:38:12 GMT
- Organization: Interpath -- Providing Internet access to North Carolina
- Message-ID: <4hmos4$ij2@news.interpath.net>
- References: <4g0elg$mdr@redstone.interpath.net> <4h0bbo$c0q@fohnix.metronet.com> <4h7ce0$ojd@news.interpath.net> <4h85sm$lm0@texas.nwlink.com> <danpop.825961872@rscernix> <313C5CD1.1209@oc.com>
- NNTP-Posting-Host: mercury.interpath.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Larry Weiss (lfw@oc.com) wrote:
-
- : > Actually, the second rule is quite good (except that '2' should be replaced
- : > by '1' :-) Magic constants embedded in the code are a huge nuisance
- : > for maintenability. [...]
-
- : I agree that there are good uses for giving a literal a name, and using
- : that name instead of repeated usage of the literal, but to make a
- : mandate that even if the literal were referenced only once you must give
- : it a name would seem too extreme.
-
- From personal experience, I think you can't be too extreme. I've been
- burned by literals before. I've come to the conclusion that magic
- numbers in the code are evil and should be done away with. Anything
- that isn't a universal, unchanging constant (like an integer being 32
- bits :)), something like a law of physics, needs to be a constant in
- the program. I always #define it, too, since C has broken const
- constants that can't be used as initializers (which defeats the whole
- point of const).
-
- I still have code that has to go through an SQL preprocessor before the
- C preprocessor which has literals in array definitions. Ugh. Some SQL
- preprocessors can handle #defines, some can't, so I have to pander to
- the lowest common denominator.
-
- Scott
-
-